package com.qf.smsplatform.strategy.mq;

import com.qf.smsplatform.common.constants.RabbitMQConstants;
import com.qf.smsplatform.common.model.StandardSubmit;
import com.qf.smsplatform.strategy.executor.StrategyExecutor;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * projectName: sms-platform
 *
 * @author: 黄睿武
 * time: 2021/8/12 23:23
 * description:监听pre_send_sms_topic队列中的消息,也就是接口模块发出的消息
 */
@Component
public class PreSendListener {

    @Autowired
    private StrategyExecutor executor;

    @RabbitListener(queues = {RabbitMQConstants.TOPIC_PRE_SEND})
    public void consume(StandardSubmit submit, Channel channel, Message message) throws IOException {
        //do something
        executor.execute(submit);


        //手动ack
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);

    }
}
